package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /*环信用户ID查询用户详细信息*/
    @GetMapping("/userinfo")
    public ResponseEntity findByHuanXinId(String huanxinId) {
        UserInfoVo vo = messagesService.findByHuanXinId(huanxinId);
        return ResponseEntity.ok(vo);
    }

    /*联系人添加*/
    @PostMapping("/contacts")
    public ResponseEntity addContacts(@RequestBody Map map) {
        //前端数据是Integer,需要转成Long
        Long friendId = Long.valueOf(map.get("userId").toString());
        messagesService.addContacts(friendId);
        return ResponseEntity.ok(null);
    }

    /*联系人列表*/
    @GetMapping("/contacts")
    public ResponseEntity getContacts(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize,
                                      String keyword) {
        PageResult pr = messagesService.getContacts(page, pagesize, keyword);
        return ResponseEntity.ok(pr);

    }

    /*公告列表*/
    @GetMapping("/announcements")
    public ResponseEntity announcements(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pr = messagesService.announcements(page, pagesize);
        return ResponseEntity.ok(pr);
    }

    /*点赞列表*/
    @GetMapping("/likes")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize) {
        int commentType=1;
        PageResult pr = messagesService.likes(page, pagesize,commentType);
        return ResponseEntity.ok(pr);
    }

    /*喜欢列表*/
    @GetMapping("/loves")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize) {
        int commentType=3;
        PageResult pr = messagesService.likes(page, pagesize,commentType);
        return ResponseEntity.ok(pr);
    }

    /*评论列表*/
    @GetMapping("/comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize){
        int commentType=2;
        PageResult pr = messagesService.likes(page, pagesize,commentType);
        return ResponseEntity.ok(pr);
    }


}
